home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / sharewar / slunec / app / httrack.exe / {app} / src_win / WinHTTrack / HtmlCtrl.cpp < prev    next >
C/C++ Source or Header  |  1999-09-10  |  3KB  |  99 lines

  1. ////////////////////////////////////////////////////////////////
  2. // Microsoft Systems Journal -- December 1999
  3. // If this code works, it was written by Paul DiLascia.
  4. // If not, I don't know who wrote it.
  5. // Compiles with Visual C++ 6.0, runs on Windows 98 and probably NT too.
  6. //
  7. #include "StdAfx.h"
  8. #include "HtmlCtrl.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. IMPLEMENT_DYNAMIC(CHtmlCtrl, CHtmlView)
  17. BEGIN_MESSAGE_MAP(CHtmlCtrl, CHtmlView)
  18.     ON_WM_DESTROY()
  19.     ON_WM_MOUSEACTIVATE()
  20. END_MESSAGE_MAP()
  21.  
  22. //////////////////
  23. // Create control in same position as an existing static control with
  24. // the same ID (could be any kind of control, really)
  25. //
  26. BOOL CHtmlCtrl::CreateFromStatic(UINT nID, CWnd* pParent)
  27. {
  28.     CStatic wndStatic;
  29.     if (!wndStatic.SubclassDlgItem(nID, pParent))
  30.         return FALSE;
  31.  
  32.     // Get static control rect, convert to parent's client coords.
  33.     CRect rc;
  34.     wndStatic.GetWindowRect(&rc);
  35.     pParent->ScreenToClient(&rc);
  36.     wndStatic.DestroyWindow();
  37.  
  38.     // create HTML control (CHtmlView)
  39.     return Create(NULL,                         // class name
  40.         NULL,                                         // title
  41.         (WS_CHILD | WS_VISIBLE ),             // style
  42.         rc,                                         // rectangle
  43.         pParent,                                     // parent
  44.         nID,                                         // control ID
  45.         NULL);                                     // frame/doc context not used
  46. }
  47.  
  48. ////////////////
  49. // Override to avoid CView stuff that assumes a frame.
  50. //
  51. void CHtmlCtrl::OnDestroy()
  52. {
  53.     // This is probably unecessary since ~CHtmlView does it, but
  54.     // safer to mimic CHtmlView::OnDestroy.
  55.     if (m_pBrowserApp) {
  56.         m_pBrowserApp->Release();
  57.         m_pBrowserApp = NULL;
  58.     }
  59.     CWnd::OnDestroy(); // bypass CView doc/frame stuff
  60. }
  61.  
  62. ////////////////
  63. // Override to avoid CView stuff that assumes a frame.
  64. //
  65. int CHtmlCtrl::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT msg)
  66. {
  67.     // bypass CView doc/frame stuff
  68.     return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, msg);
  69. }
  70.  
  71. //////////////////
  72. // Override navigation handler to pass to "app:" links to virtual handler.
  73. // Cancels the navigation in the browser, since app: is a pseudo-protocol.
  74. //
  75. void CHtmlCtrl::OnBeforeNavigate2( LPCTSTR lpszURL,
  76.     DWORD nFlags,
  77.     LPCTSTR lpszTargetFrameName,
  78.     CByteArray& baPostedData,
  79.     LPCTSTR lpszHeaders,
  80.     BOOL* pbCancel )
  81. {
  82.     const char APP_PROTOCOL[] = "app:";
  83.     int len = _tcslen(APP_PROTOCOL);
  84.     if (_tcsnicmp(lpszURL, APP_PROTOCOL, len)==0) {
  85.         OnAppCmd(lpszURL + len);
  86.         *pbCancel = TRUE;
  87.     }
  88. }
  89.  
  90. //////////////////
  91. // Called when the browser attempts to navigate to "app:foo"
  92. // with "foo" as lpszWhere. Override to handle app commands.
  93. //
  94. void CHtmlCtrl::OnAppCmd(LPCTSTR lpszWhere)
  95. {
  96.     // default: do nothing
  97. }
  98.  
  99.